package com.boilermaker.demo.controller;

import com.boilermaker.demo.model.*;
import com.boilermaker.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/book")
@RestController
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/getListByPage")
    public Response<PageResponse<Book>> getListByPage(PageRequest pageRequest) {
        PageResponse<Book> pageResponse = bookService.getListByPage(pageRequest);
        return ResponseFactory.success(pageResponse);
    }

    @RequestMapping("/addBook")
    public boolean addBook(Book book) {
        return bookService.checkAndInsertBook(book);
    }

    @RequestMapping("/updateBook")
    public boolean updateBook(Book book) {
        return bookService.updateBook(book);
    }

    @RequestMapping("/selectBookById")
    public Book selectBookById(@RequestParam("bookId") Integer id) {
        return bookService.selectBookById(id);
    }

    @RequestMapping("/deleteBooks")
    public boolean deleteBooks(@RequestParam List<Integer> ids) {
        return bookService.deleteBooks(ids);
    }
}
